package com.ming.easyDevelop.service.impl;

import com.ming.easyDevelop.mappers.AddressesMapper;
import com.ming.easyDevelop.entity.po.Addresses;
import com.ming.easyDevelop.entity.query.AddressesQuery;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ming.easyDevelop.service.AddressesService;
import com.ming.easyDevelop.entity.vo.PaginationResVo;
import com.ming.easyDevelop.entity.baseEnum.PageSize;
import com.ming.easyDevelop.entity.query.base.SimplePage;
@Service("addressesService")
public class AddressesServiceImpl implements AddressesService {
	private final AddressesMapper<Addresses, AddressesQuery> addressesMapper;

	public AddressesServiceImpl(AddressesMapper addressesMapper){
		this.addressesMapper = addressesMapper;
	}
	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<Addresses> findListByParam(AddressesQuery query){
		return this.addressesMapper.selectList(query);
	}

	/**
	 * 根据条件查询数量
	 */
	@Override
	public Long findCountByParam(AddressesQuery query){
		return this.addressesMapper.selectCount(query);
	}

	/**
	 * 根据条件分页查询列表
	 */
	@Override
	public PaginationResVo<Addresses> findListByPage(AddressesQuery query){
		Long count = this.findCountByParam(query);
		int pageSize = query.getPageSize() == null ? PageSize.SIZE20.getSize() : query.getPageSize();
		SimplePage simplePage = new SimplePage(query.getPageNo(), pageSize, Math.toIntExact(count));
		List<Addresses> res = this.findListByParam(query);
		return new PaginationResVo<Addresses>(query.getSimplePage().getPageNo(), query.getSimplePage().getPageSize(), query.getSimplePage().getCountTotal(), query.getSimplePage().getPageTotal(), res);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Long addBatch(List<Addresses> list){
		return this.addressesMapper.insertBatch(list);
	}

	/**
	 * 新增
	 */
	@Override
	public Long add(Addresses bean){
		return this.addressesMapper.insert(bean);
	}

	/**
	 * 新增
	 */
	@Override
	public Long addOrUpdate(Addresses bean){
		return this.addressesMapper.insertOrUpdate(bean);
	}

	/**
	 * 新增
	 */
	@Override
	public Long addOrUpdateBatch(List<Addresses> list){
		return this.addressesMapper.insertOrUpdateBatch(list);
	}

	/**
	 * 根据AddressID查询
	 */
	@Override
	public Addresses getByAddressID(Integer addressID){
		return this.addressesMapper.selectByAddressID(addressID);
	}

	/**
	 * 根据AddressID更新
	 */
	@Override
	public Long updateByAddressID(Addresses bean, Integer addressID){
		return this.addressesMapper.updateByAddressID(bean,addressID);
	}

	/**
	 * 根据AddressID删除
	 */
	@Override
	public Long deleteByAddressID(Integer addressID){
		return this.addressesMapper.deleteByAddressID(addressID);
	}

	/**
	 * 根据UserIDAndAddressType查询
	 */
	@Override
	public Addresses getByUserIDAndAddressType(Integer userID, String addressType){
		return this.addressesMapper.selectByUserIDAndAddressType(userID, addressType);
	}

	/**
	 * 根据UserIDAndAddressType更新
	 */
	@Override
	public Long updateByUserIDAndAddressType(Addresses bean, Integer userID, String addressType){
		return this.addressesMapper.updateByUserIDAndAddressType(bean,userID, addressType);
	}

	/**
	 * 根据UserIDAndAddressType删除
	 */
	@Override
	public Long deleteByUserIDAndAddressType(Integer userID, String addressType){
		return this.addressesMapper.deleteByUserIDAndAddressType(userID, addressType);
	}

}
